package com.action;

import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;

import com.entity.Address;
import com.entity.User;
import com.service.AddressService;
import com.service.Impl.AddressServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

@Controller
@Scope("prototype")
public class AddressAction {
	@Autowired
	private AddressService service;
	private Integer userId;
	private List<Address> address;
	private Address a;
	public Address getA() {
		return a;
	}
	public void setA(Address a) {
		this.a = a;
	}
	public Integer getUserId() {
		return userId;
	}
	public void setUserId(Integer userId) {
		this.userId = userId;
	}
	public List<Address> getAddress() {
		return address;
	}
	public void setAddress(List<Address> address) {
		this.address = address;
	}
	public String showByUser(){

		address=service.showByUser(userId);
		return "showByUser";
	}
	public String showAddress(){

		address=service.showByUser(userId);
		return "showAddress";
	}
	public String showAddressByUser(){
		Map<String, Object> session = ActionContext.getContext().getSession();
		User u=(User)session.get("u");
		Integer id=u.getUserId();
		address=service.showByUser(id);
		return "showAddressByUser";
	}
	public String insertAddress(){
		Map<String, Object> session = ActionContext.getContext().getSession();
		User u = (User) session.get("u");
		a.setUserId(u.getUserId());
		service.insertAddress(a);
		return "insertAddress";
	}
}
